-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix: add timeout to git commands to prevent Zed extension hang on Win… #7586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
fix: add timeout to git commands to prevent Zed extension hang on Win… #7586
Conversation
…dows When opening Git repositories in the Zed editor on Windows, the OpenCode extension would hang indefinitely on "Loading..." due to git commands blocking without timeout in Project.fromDirectory(). This adds a gitWithTimeout() helper that wraps git commands with a 5-second timeout, allowing graceful fallback to non-git behavior instead of hanging. The three affected git commands are: - git rev-list --max-parents=0 --all (project ID generation) - git rev-parse --show-toplevel (repository root detection) - git rev-parse --git-common-dir (worktree detection) Tested on Windows with Zed 0.218.6 and confirms the extension now loads successfully in Git repositories.
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
|
Built this locally on Windows 11 and it fixes the hang in existing Zed projects. The git commands were blocking indefinitely before - now they timeout gracefully and Zed proceeds normally. Thanks for the fix. |
Happy to help ! |
|
Any idea why it hangs infinitely? Ideally we fix that because I think doing this will lead to unexpected outcomes otherwise... |
I've found this as the most promising aswer for this question:
The failure process:
|
Summary
Fixes the OpenCode extension hanging indefinitely on "Loading..." when opening Git repositories in Zed editor on Windows.
Problem
When opening a Git repository in Zed on Windows, three git commands in
Project.fromDirectory()would hang indefinitely:git rev-list --max-parents=0 --all(project ID generation)git rev-parse --show-toplevel(repository root detection)git rev-parse --git-common-dir(worktree detection)This caused the Zed extension to freeze during initialization, preventing users from using the OpenCode assistant in any Git repository.
Root Cause
The issue was initially reported as a Zed bug in zed-industries/zed#43335, but investigation revealed it was an OpenCode bug. The git commands were executed without any timeout mechanism, causing indefinite hangs on Windows when called through the Zed Agent Communication Protocol.
Solution
Added a
gitWithTimeout()helper function that wraps git command promises with a 5-second timeout usingPromise.race(). When a timeout occurs:log.warn)The timeout is conservative enough (5 seconds) that it won't affect normal git operations on any platform, but prevents indefinite hangs.
Testing
Related Issues
Changes
gitWithTimeout()helper function inpackages/opencode/src/project/project.tsFixes #7587